require('./home.less')
require('../../assets/css/index.less')
require('../../assets/fonts/iconfont.css')



const dom = require('../../utils/dom')

const https = require('../../utils/https');
const local = require('../../utils/local');
import Swiper, { Pagination, Autoplay } from 'swiper';
import 'swiper/swiper-bundle.css';


dom.ready(function() {
    dom.bMenu("home")
    Swiper.use([Pagination, Autoplay])
    var mySwiper = new Swiper('.swiper', {

        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },

        // 如果需要滚动条
        scrollbar: {
            el: '.swiper-scrollbar',
        },
    })



    function getUserInfo() {
        https.get('/api/user/info', function(res) {
            // console.log(res);
            let {
                errno,
                data
            } = res;
            console.log(res, errno, data);

            let { ranking, clockCount, badges } = data;
            console.log(ranking, clockCount, badges);
            console.log(dom.gete(".clockCounttext"));
            dom.gete(".rankingtxt").innerHTML = ranking;
            dom.gete(".clockCounttext").innerHTML = clockCount;
            dom.gete(".badgestxt").innerHTML = badges;
        })
    }

    //当页面加载时就获取当前用户信息

    getUserInfo()


    function getClock() {
        https.get("/api/user/clockInInfo", function(res) {
            console.log(res);
            let { data, errno } = res;
            if (errno == 0) {
                data.isClockIn ? dom.gete("button").innerHTML = "已打卡" : dom.gete("button").innerHTML = "今日打卡"
            }
        })
    }
    getClock()


    // bom.addevent("button",https.post("/api/user/clockIn")





})